﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.金蝶
{
    public class 金蝶BOMService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="styleName"></param>
        /// <param name="materialNo"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public static List<EBOMGroupQueryFacadeDTO> getSpuBom(String styleName,String materialNo,Double orderNumber)
        {
            return
                FunctionHelper.JsonDeserialization<List<EBOMGroupQueryFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/bom/getSpuBom?styleName=" + styleName
                                                 + "&materialNo=" + materialNo
                                                 + "&orderNumber=" + orderNumber
                        )
                    );
        }
        /// <summary>
        /// 根据订单id取订单对应的BOM展示
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static List<EBOMGroupQueryFacadeDTO> getEBOMGroupQueryFacadeByOrderId(String orderId)
        {
            return
                FunctionHelper.JsonDeserialization<List<EBOMGroupQueryFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/bom/getEBOMGroupQueryFacadeByOrderId?orderId=" + orderId
                        )
                    );
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static List<EBOMGroupQueryFacadeDTO> getEBOMGroupQueryFacadeByOrderIdWithFnumber(String orderId)
        {
            return
                FunctionHelper.JsonDeserialization<List<EBOMGroupQueryFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/bom/getEBOMGroupQueryFacadeByOrderIdWithFnumber?orderId=" + orderId
                        )
                    );
        }
        /// <summary>
        /// 查询一组订单下的面料出库申请
        /// </summary>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public static List<MBOMGroupQueryFacadeDTO> getMBOMGroupQueryFacadeByOrderIds(List<String> orderIds)
        {
            String xx = FunctionHelper.JsonSerialization(orderIds);
            return
                FunctionHelper.JsonDeserialization<List<MBOMGroupQueryFacadeDTO>>(
                    RestCall.PostHttp(
                           URL.接口url + "/bom/getMBOMGroupQueryFacadeByOrderIds",
                           FunctionHelper.JsonSerialization(orderIds)
                           )
                );
        }
        /// <summary>
        /// 取BOM明细一览
        /// </summary>
        /// <returns></returns>
        public static List<BomDetailTitleDTO> getBomDetailAll()
        {
            return
                FunctionHelper.JsonDeserialization<List<BomDetailTitleDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/bom/getBomDetailAll"
                        )
                    );
        }
    }
    

    /// <summary>
    /// 订单对应的BOM展示
    /// </summary>
    public class EBOMGroupQueryFacadeDTO
    {
        public int fid { get; set; }    //  金蝶物料分组id
        public String fnumber { get; set; } //  金蝶物料分组名称
        public Boolean isFabric { get; set; }   //  是否面料
        public List<EBomInventoryQueryDTO> eBomInventoryQueryDTOList { get; set; } = new List<EBomInventoryQueryDTO>();
        public EBOMGroupQueryFacadeDTO()
        {

        }
    }

    public class EBomInventoryQueryDTO
    {
        public int fpkid { get; set; }
        public int fmaterialid { get; set; }
        public int flocaleid { get; set; }
        public String fname { get; set; }   //  编码
        public String fnumber { get; set; }
        public String fspecification { get; set; }
        public String fdescription { get; set; }    //  名称
        public int fuseorgid { get; set; }
        public String fforbidreason { get; set; }
        public Double quantity { get; set; }    //  库存数量
        public Double ffixscrapqty { get; set; }    //  固定损耗
        //  辅料单独
        public String subMaterialNumber { get; set; }//品番（供应商编码）
        public String subMaterialSupplier { get; set; }//供应商
        public String subMaterialSpecDesc { get; set; }//规格描述
        public EBomInventoryQueryDTO()
        {

        }
    }
    public class MBOMGroupQueryFacadeDTO
    {
        public int fid { get; set; }    //  金蝶物料分组id
        public String fnumber { get; set; }   //  金蝶物料分组名称
        public Boolean isFabric { get; set; }   //  是否面料
        public String styleName { get; set; }
        public String materialNo { get; set; }
        public Double orderNumber { get; set; }
        public Dictionary<String, MBomInventoryQueryDTO> mBomInventoryQueryDTOS { get; set; } = new Dictionary<string, MBomInventoryQueryDTO>();

        public MBOMGroupQueryFacadeDTO()
        {

        }
    }
    public class MBomInventoryQueryDTO
    {
        public String styleName { get; set; }
        public String materialNo { get; set; }
        public Double orderNumber { get; set; }
        public int fpkid { get; set; }
        public int fmaterialid { get; set; }
        public int flocaleid { get; set; }
        public String fname { get; set; }   //  赋义编码 
        public String fspecification { get; set; }  //  名称
        public String fdescription { get; set; }    //  规格 
        public int fuseorgid { get; set; }
        public String fforbidreason { get; set; }
        public Double quantity { get; set; }    //  库存数量
        public Double ffixscrapqty { get; set; }    //  固定损耗
        //  辅料单独
        public String subMaterialSupplier { get; set; }//供应商    
        public String fnumber { get; set; }
        public MBomInventoryQueryDTO()
        {

        }
    }
    public class BomStockOutDTO
    {
        public String fGroupNumber { get; set; } //  金蝶物料分组名称
        public Boolean isFabric { get; set; }   //  是否面料
        public String fnumber { get; set; }   //
        public String fname { get; set; }   //  赋义编码 
        public Double ffixscrapqty { get; set; }    //  固定损耗
        public Double orderNumber { get; set; }
        public BomStockOutDTO()
        {

        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="mBOMGroupQueryFacadeDTO"></param>
        /// <param name="mBomInventoryQueryDTO"></param>
        public BomStockOutDTO(MBOMGroupQueryFacadeDTO mBOMGroupQueryFacadeDTO, MBomInventoryQueryDTO mBomInventoryQueryDTO)
        {
            this.fGroupNumber = mBOMGroupQueryFacadeDTO.fnumber;
            this.isFabric = mBOMGroupQueryFacadeDTO.isFabric;
            this.fnumber = mBomInventoryQueryDTO.fnumber;
            this.fname = mBomInventoryQueryDTO.fname;
            this.ffixscrapqty = mBomInventoryQueryDTO.ffixscrapqty;
            this.orderNumber = mBomInventoryQueryDTO.orderNumber;
        }
        /// <summary>
        /// 累加
        /// </summary>
        /// <param name="mBomInventoryQueryDTO"></param>
        /// <returns></returns>
        public BomStockOutDTO build(MBomInventoryQueryDTO mBomInventoryQueryDTO)
        {
            this.ffixscrapqty = mBomInventoryQueryDTO.ffixscrapqty;
            this.orderNumber = mBomInventoryQueryDTO.orderNumber;
            return this;
        }
    }
    public class BomStockOutWithStyleDTO
    {
        public String fGroupNumber { get; set; } //  金蝶物料分组名称
        public Boolean isFabric { get; set; }   //  是否面料
        public String fnumber { get; set; }   //
        public String fname { get; set; }   //  赋义编码 
        public Double ffixscrapqty { get; set; }    //  固定损耗
        public Double orderNumber { get; set; }
        public String styleName { get; set; }
        public String materialNo { get; set; }
        public Double quantity { get; set; }    //  库存数量
        public String fspecification { get; set; }  //  名称
        public String fdescription { get; set; }    //  规格 

        public BomStockOutWithStyleDTO()
        {

        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="mBOMGroupQueryFacadeDTO"></param>
        /// <param name="mBomInventoryQueryDTO"></param>
        public BomStockOutWithStyleDTO(MBOMGroupQueryFacadeDTO mBOMGroupQueryFacadeDTO, MBomInventoryQueryDTO mBomInventoryQueryDTO)
        {
            this.fGroupNumber = mBOMGroupQueryFacadeDTO.fnumber;
            this.isFabric = mBOMGroupQueryFacadeDTO.isFabric;
            this.fnumber = mBomInventoryQueryDTO.fnumber;
            this.fname = mBomInventoryQueryDTO.fname;
            this.ffixscrapqty = mBomInventoryQueryDTO.ffixscrapqty;
            this.orderNumber = mBomInventoryQueryDTO.orderNumber;
            this.styleName = mBomInventoryQueryDTO.styleName;
            this.materialNo = mBomInventoryQueryDTO.materialNo;
            this.quantity = mBomInventoryQueryDTO.quantity;
            this.fspecification = mBomInventoryQueryDTO.fspecification;
            this.fdescription = mBomInventoryQueryDTO.fdescription;
        }
        /// <summary>
        /// 累加
        /// </summary>
        /// <param name="mBomInventoryQueryDTO"></param>
        /// <returns></returns>
        public BomStockOutWithStyleDTO build(MBomInventoryQueryDTO mBomInventoryQueryDTO)
        {
            this.ffixscrapqty = mBomInventoryQueryDTO.ffixscrapqty;
            this.orderNumber = mBomInventoryQueryDTO.orderNumber;
            return this;
        }
    }

    public class BDMATERIALGROUPDTO
    {
        public int FID { get; set; }
        public String FNUMBER { get; set; }
        public String FGROUPID { get; set; }
        public int FPARENTID { get; set; }
        public String FFULLPARENTID { get; set; }
        public int FLEFT { get; set; }
        public int FRIGHT { get; set; }
        public Double FPOINTRATE { get; set; }
        public String FShowPOS { get; set; }
        public String FShowBigScreen { get; set; }
        public String FPICTUREUPLOAD { get; set; }
        public String FPICTUREURL { get; set; }
        public String FONLINENAME { get; set; }
        public BDMATERIALGROUPDTO()
        {

        }
    }
    public class BomDetailEntryDTO
    {
        public String id { get; set; }
        public String groupName { get; set; } //  金蝶物料分组名称
        public Boolean isFabric { get; set; }   //  是否面料
                                                //  BOM信息
        public int fpkid { get; set; }
        public int fmaterialid { get; set; }
        public int flocaleid { get; set; }
        public String fname { get; set; }   //  赋义编码  @see    top.toptimus.postgresCloudService.jpa.dao.postgresCloud.material.SubMaterialSkuDao.subMaterialCode
        public String fspecification { get; set; }  //  名称
        public String fdescription { get; set; }    //  规格  @see top.toptimus.postgresCloudService.jpa.dao.postgresCloud.material.SubMaterialSkuDao.subMaterialSpec
        public int fuseorgid { get; set; }
        public String fforbidreason { get; set; }
        public Double ffixscrapqty { get; set; }    //  固定损耗
                                                    //  辅料单独
        public String subMaterialSupplier { get; set; }//供应商    @top.toptimus.postgresCloudService.jpa.dao.postgresCloud.material.SubMaterialSpuDao.subMaterialSupplier
        public String fnumber { get; set; }

        public Double stockQty { get; set; }    //  金蝶库存数
        public Double purchaseQty { get; set; } //  在途数
        public BomDetailEntryDTO()
        {

        }
    }
    public class BomDetailTitleDTO
    {
        public String styleCode { get; set; }
        public String fabricNo { get; set; }

        public List<BomDetailEntryDTO> bomDetailEntryDTOList { get; set; } = new List<BomDetailEntryDTO>();
        public BomDetailTitleDTO()
        {

        }
    }
}
